package main

import (
	"log"
	"log/slog"
	"os"
	"path"
	"time"

	"gitee.com/asphodelus_dev/go-s3-local/fs"

	"gitlab.com/greyxor/slogor"

	httpd "gitee.com/asphodelus_dev/go-s3-local/http"
)

func main() {
	slog.SetDefault(slog.New(slogor.NewHandler(os.Stderr, slogor.Options{
		TimeFormat: time.Stamp,
		Level:      slog.LevelDebug,
		ShowSource: true,
	})))

	dataDir := "data"
	if err := os.MkdirAll(dataDir, 0o700); err != nil {
		log.Fatalf("failed to create path for Raft storage: %s", err.Error())
	}

	httpAddr := ":8080"
	fs.InitFs(path.Join(dataDir, "file"))
	h := httpd.New(httpAddr, dataDir)
	if err := h.Start(); err != nil {
		log.Fatalf("failed to start HTTP service: %s", err.Error())
	}
}
